package cn.gjxblog.controller;

import cn.gjxblog.api.CommentServerFegin;
import cn.gjxblog.model.dto.CommentDTO;
import cn.gjxblog.model.entity.Blog;
import cn.gjxblog.model.UserContext;
import cn.gjxblog.model.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 作用:
 * 作者:gjx
 * 版本:V1.0
 * 创建时间: 2019/1/19 18:13
 */
@Controller
public class CommentController {

    @Autowired
    private CommentServerFegin commentServerFegin;

    @RequestMapping(value="/comment/leaveComment")
    public String leaveComment(String content,String houseId,ModelMap modelMap){
        User user = UserContext.getUser();
        String userId =  user.getId();
        CommentDTO commentDTO = new CommentDTO();
        commentDTO.setHouseId(houseId);
        commentDTO.setContent(content);
        commentDTO.setUserId(userId);
        commentDTO.setType(1);
        commentServerFegin.addComment(commentDTO);
        return "redirect:/house/detail?id=" + houseId;
    }


    @RequestMapping(value="/comment/leaveBlogComment")
    public String leaveBlogComment(String content,String  blogId,ModelMap modelMap){
        User user = UserContext.getUser();
        String userId =  user.getId();
        CommentDTO commentDTO = new CommentDTO();
        commentDTO.setBlogId(blogId);
        commentDTO.setContent(content);
        commentDTO.setUserId(userId);
        commentServerFegin.addComment(commentDTO);
        return "redirect:/blog/detail?id=" + blogId;
    }


}
